package com.wngbms._01_bytecode;

public class LocalVariableTest {
    
    public static void main(String[] args) {
        MovingAverage ma = new MovingAverage();
        int num1 = 5;
        int num2 = 7;
        ma.submit(num1);
        ma.submit(num2);
        double avg = ma.getAvg();
        System.out.println(avg);
    }
}

/**
 * javap -c .\bin\com\wngbms\LocalVariableTest.class
 * 
 * public class com.wngbms.LocalVariableTest {
  public com.wngbms.LocalVariableTest();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: new           #16                 // class com/wngbms/MovingAverage
       3: dup
       4: invokespecial #18                 // Method com/wngbms/MovingAverage."<init>":()V
       7: astore_1                          // 将ma存放在局部变量表1号位置
       8: iconst_5                          // 将数字5压栈
       9: istore_2                          // 将数字5出栈并存放在局部变量表2号位置
      10: bipush        7                   // 将数字7压栈
      12: istore_3                          // 将数字7出栈并存放在局部变量表3号位置
      13: aload_1                           // 将局部变量表1号位置ma引用压栈
      14: iload_2                           // 将局部变量表2号位置数字5压栈
      15: i2d                               // 类型转换
      16: invokevirtual #19                 // Method com/wngbms/MovingAverage.submit:(D)V
      19: aload_1                           // 将局部变量表1号位置ma引用压栈
      20: iload_3                           // 将局部变量表3号位置数字7压栈
      21: i2d                               // 类型转换
      22: invokevirtual #19                 // Method com/wngbms/MovingAverage.submit:(D)V
      25: aload_1
      26: invokevirtual #23                 // Method com/wngbms/MovingAverage.getAvg:()D
      29: dstore        4                   // 将avg保存在局部变量表4号位置
      31: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      34: dload         4                   // 将局部变量表4号位置avg压栈
      36: invokevirtual #33                 // Method java/io/PrintStream.println:(D)V
      39: return
}
 */

/**
 * javap -c -verbose .\bin\com\wngbms\LocalVariableTest.class
 * 
 * Classfile /D:/Code/_01_geektime/_01_geektime/bin/com/wngbms/LocalVariableTest.class
  Last modified 2022-2-25; size 778 bytes
  MD5 checksum bcb0acd982bbbc3baef6393654990c70
  Compiled from "LocalVariableTest.java"
public class com.wngbms.LocalVariableTest
  minor version: 0
  major version: 52
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Class              #2             // com/wngbms/LocalVariableTest
   #2 = Utf8               com/wngbms/LocalVariableTest
   #3 = Class              #4             // java/lang/Object
   #4 = Utf8               java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = Utf8               Code
   #8 = Methodref          #3.#9          // java/lang/Object."<init>":()V
   #9 = NameAndType        #5:#6          // "<init>":()V
  #10 = Utf8               LineNumberTable
  #11 = Utf8               LocalVariableTable
  #12 = Utf8               this
  #13 = Utf8               Lcom/wngbms/LocalVariableTest;
  #14 = Utf8               main
  #15 = Utf8               ([Ljava/lang/String;)V
  #16 = Class              #17            // com/wngbms/MovingAverage
  #17 = Utf8               com/wngbms/MovingAverage
  #18 = Methodref          #16.#9         // com/wngbms/MovingAverage."<init>":()V
  #19 = Methodref          #16.#20        // com/wngbms/MovingAverage.submit:(D)V
  #20 = NameAndType        #21:#22        // submit:(D)V
  #21 = Utf8               submit
  #22 = Utf8               (D)V
  #23 = Methodref          #16.#24        // com/wngbms/MovingAverage.getAvg:()D
  #24 = NameAndType        #25:#26        // getAvg:()D
  #25 = Utf8               getAvg
  #26 = Utf8               ()D
  #27 = Fieldref           #28.#30        // java/lang/System.out:Ljava/io/PrintStream;
  #28 = Class              #29            // java/lang/System
  #29 = Utf8               java/lang/System
  #30 = NameAndType        #31:#32        // out:Ljava/io/PrintStream;
  #31 = Utf8               out
  #32 = Utf8               Ljava/io/PrintStream;
  #33 = Methodref          #34.#36        // java/io/PrintStream.println:(D)V
  #34 = Class              #35            // java/io/PrintStream
  #35 = Utf8               java/io/PrintStream
  #36 = NameAndType        #37:#22        // println:(D)V
  #37 = Utf8               println
  #38 = Utf8               args
  #39 = Utf8               [Ljava/lang/String;
  #40 = Utf8               ma
  #41 = Utf8               Lcom/wngbms/MovingAverage;
  #42 = Utf8               num1
  #43 = Utf8               I
  #44 = Utf8               num2
  #45 = Utf8               avg
  #46 = Utf8               D
  #47 = Utf8               SourceFile
  #48 = Utf8               LocalVariableTest.java
{
  public com.wngbms.LocalVariableTest();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #8                  // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 3: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   Lcom/wngbms/LocalVariableTest;

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=3, locals=6, args_size=1
         0: new           #16                 // class com/wngbms/MovingAverage
         3: dup
         4: invokespecial #18                 // Method com/wngbms/MovingAverage."<init>":()V
         7: astore_1
         8: iconst_5
         9: istore_2
        10: bipush        7
        12: istore_3
        13: aload_1
        14: iload_2
        15: i2d
        16: invokevirtual #19                 // Method com/wngbms/MovingAverage.submit:(D)V
        19: aload_1
        20: iload_3
        21: i2d
        22: invokevirtual #19                 // Method com/wngbms/MovingAverage.submit:(D)V
        25: aload_1
        26: invokevirtual #23                 // Method com/wngbms/MovingAverage.getAvg:()D
        29: dstore        4
        31: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
        34: dload         4
        36: invokevirtual #33                 // Method java/io/PrintStream.println:(D)V
        39: return
      LineNumberTable:
        line 6: 0
        line 7: 8
        line 8: 10
        line 9: 13
        line 10: 19
        line 11: 25
        line 12: 31
        line 13: 39
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      40     0  args   [Ljava/lang/String;
            8      32     1    ma   Lcom/wngbms/MovingAverage;
           10      30     2  num1   I
           13      27     3  num2   I
           31       9     4   avg   D
}
SourceFile: "LocalVariableTest.java"
 */